﻿<%@ Page Language="VB" AutoEventWireup="false" Inherits="WebCompras.Paginas_prueba" Codebehind="prueba.aspx.vb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Página sin título</title>
</head>
<script LANGUAGE=javascript>
function exportToXL(eSrc) {
var oExcel; 
var oExcelSheet; 
var oWkBooks;
var cols; 
oExcel = new ActiveXObject('Excel.Application');
oWkBooks = oExcel.Workbooks.Add;
oExcelSheet = oWkBooks.Worksheets(1);
oExcelSheet.Activate();
if (eSrc.tagName != 'TABLE') {
alert('No ha sido posible exportar la tabla a excell');
return false;
}
cols = Math.ceil(eSrc.cells.length / eSrc.rows.length);
for (var i = 0; i < eSrc.cells.length; i ++)
{
var c, r;
r = Math.ceil((i+1) / cols);
c = (i+1)-((r-1)*cols)
if (eSrc.cells(i).tagName == 'TH') { 
oExcel.ActiveSheet.Cells(r,c).Font.Bold = true;
oExcel.ActiveSheet.Cells(r,c).Interior.Color = 14474460; 
}
if (eSrc.cells(i).childNodes.length > 0 && eSrc.cells(i).childNodes(0).tagName == "B") 
oExcel.ActiveSheet.Cells(r,c).Font.Bold = true;
oExcel.ActiveSheet.Cells(r,c).Value = eSrc.cells(i).innerText;
}
oExcelSheet.Application.Visible = true;
}
</script>
<body>
    <form id="form1" runat="server">
<TABLE id=idTable cols=3 name=idTable>
<TR>
<TH>Titulo 1</TH>
<TH>Titulo 2</TH>
<TH>Titulo 3</TH>
</TR>
<TR><TD>Celda 1</TD><TD>Celda 5</TD><TD>Celda 5</TD></TR>
<TR><TD><b>Celda 2</b></TD><TD>Celda 6</TD><TD>Celda 5</TD></TR>
<TR><TD>Celda 3</TD><TD>Celda 7</TD><TD>Celda 5</TD></TR>
<TR><TD>Celda 4</TD></TR>
</TABLE>
<TABLE id=idTable1 cols=3 name=idTable1>
<TR>
<TH>Titulo 1</TH>
<TH>Titulo 2</TH>
<TH>Titulo 3</TH>
</TR>
<TR><TD>Celda 1</TD><TD>Celda 5</TD><TD>Celda 5</TD></TR>
<TR><TD><b>Celda 2</b></TD><TD>Celda 6</TD><TD>Celda 5</TD></TR>
<TR><TD>Celda 3</TD><TD>Celda 7</TD><TD>Celda 5</TD></TR>
<TR><TD>Celda 4</TD></TR>
</TABLE>
    </form>
    <INPUT type="button" value="Exportar" id=button1 name=button1 onCLick="exportToXL(form1.all('idTable'))">
</body>
</html>
